#include "DSPGroupBuilder.h"
#include "DSPGroup.h"
#include "DSPParallel.h"
#include "DSPChain.h"
#include "IIRUtil.h"
#include "BiquadIIR.h"
#include "IIR.h"

namespace yzrilyzr_dsp{
	
	DSPGroupBuilder & DSPGroupBuilder::begin(int type){
		auto old=ptr;
		if(type == TYPE_CHAIN){
			ptr=std::make_shared<DSPChain>();
		}else if(type == TYPE_PARALLEL){
			ptr=std::make_shared<DSPParallel>();
		}
		if(old!=nullptr){
			ptr->add(old);
		}
		return *this;
	}
	DSPGroupBuilder & DSPGroupBuilder::add(DSPPtr d){
		ptr->add(d);
		return *this;
	}
	DSPGroupBuilder & DSPGroupBuilder::biquad(u_sample_rate sampleRate, FilterPassType type, u_freq f1, u_sample q, u_sample gain){
		return add(IIRUtil::newBiquadIIRFilter(IIRUtil::limitFreq(sampleRate, f1), sampleRate, q, gain, type));
	}
	std::shared_ptr<DSPGroup> DSPGroupBuilder::build(){
		return ptr;
	}
}